<template>
    <el-dialog title="添加单位" v-model="dialogVisible" width="500" destroy-on-close draggable align-center :before-close="handleClose">
        <el-form v-model="queryForm" style="margin-top: 40px">
            <el-form-item label="名称">
                <el-input v-model="queryForm.name"></el-input>
            </el-form-item>
            <el-form-item label="主单位">
<!--                单选按钮，是或者不是-->
                <el-radio-group v-model="queryForm.mainUnit">
                    <el-radio label="是" value="1">是</el-radio>
                    <el-radio label="否" value="0">否</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="备注">
                <el-input v-model="queryForm.comments"></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button type="primary" @click="handleAdd">
                    保存
                </el-button>
                <el-button @click="handleClose">取消</el-button>

            </div>
        </template>
    </el-dialog>
</template>
<script>
import unitAPI from "@/util/request-md/unit/unit.js"
export default {
    emits:['callClosed','calledAddSuccess'],
    props:['visible'],
    watch:{
        visible(val){
            this.dialogVisible = val;
        }
    },
    data() {
        return {
            dialogVisible:false,
            queryForm: {
                name:'',
                mainUnit:'',
                comments:'',
            }
        }
    },
    methods:{
        handleClose(){
            this.$emit('callClosed');
        },
        handleAdd(){
            unitAPI.add(this.queryForm,(res)=>{
                if (res.code === 200){
                //     操作成功
                    this.$message.success("添加成功");
                    this.dialogVisible = false;
                    this.$emit('calledAddSuccess');
                }else{
                    this.$message.error("网络不佳，请稍后再试");
                    this.$emit('callClosed');
                }
            });
        }
    }
}
</script>
<style>

</style>
